/*  File Name	: DuplexListTest.cpp
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-10-12
 *  Description:
 */
#ifndef DuplexListTest_CPP
#define DuplexListTest_CPP
#include "CommonStruct.h"
#include <stdlib.h>

DuplexList d_list(10);

struct Dlist
{
	Dlist()
	{
		i =0;
	}
	int i;
};

void init_list()
{
	int size = 25;

	for(int i=0;i<size;i++)
	{
		Dlist *b = new Dlist();
		b->i=i+1;
		d_list.put_obj(b);
	}
}

static void* get_list(void*)
{
	Dlist *list = NULL;
	while(true)
	{
		d_list.get_obj((void*&)list);
		std::cout<<"=====get_list:"<<list->i<<std::endl;
		d_list.put_obj(list);
		sleep(1);
	}
	return NULL;
}

static void* put_list(void*)
{
	int size = 0;
	while(true)
	{
		for(int i=0;i<15;i++)
		{
			Dlist *b = new Dlist();
			b->i=(++size);
			d_list.put_obj(b);
			std::cout<<"=====put_list:"<<b->i<<std::endl;
		}
		sleep(10);
	}
	return NULL;
}

//int main()
//{
//	pthread_t t1,t2;
//	pthread_create(&t1,NULL,put_list,NULL);
//	pthread_create(&t2,NULL,get_list,NULL);
//	pthread_join(t1,NULL);
//	pthread_join(t2,NULL);
//	return 0;
//}

#endif ///DuplexListTest_CPP
